﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblJobNoteDAO
    {
        DBService _db = null;
        public TblJobNoteDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable GetJobNotes(int JobID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblJobNotes where JobID = @JobID order by DateEntered DESC",
                    new string [] {"@JobID"},
                    new object [] {JobID}, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable InsUp_JobNote(TblJobNotes jobNotes, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_GetJobNote_InsUp",
                     new string[] { "@JobNoteID", "@JobID", "@DateEntered", "@NoteType", "@Notes", "@StatusJobNotes", "@StatusJob", "@Mode" },
                     new object[] { jobNotes.IDJobNote, jobNotes.JobID, jobNotes.DateEntered, jobNotes.NoteType,
                          jobNotes.Notes, jobNotes.StatusJobNote, jobNotes.StatusJob, mode}, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable GetJobNoteAll()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblJobNotes_GetList", false, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable Update(int StatusJob, string IDJobNote)
        {
            DataTable dt = null;
            try
            {

                dt = _db.ExeSP_DataTable("Update TblJobNotes set StatusJob = @StatusJob, StatusJobNote='Has been Actioned' where IDJobNote = @IDJobNote",
                    new string[] { "@StatusJob", "@IDJobNote" },
                    new object[] { StatusJob, IDJobNote }, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
        //update JobStatus khi Status = Actioned
        public DataTable Update_JobStaus(int JobID)
        {
            DataTable dt = null;
            try
            {

                dt = _db.ExeSP_DataTable("Update TblJobNotes set StatusJob = 1 where JobID = @JobID",
                    new string[] { "@JobID" },
                    new object[] { JobID }, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
        public DataTable GetJobNoteID(string IDJobNote)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblJobNotes where IDJobNote = @IDJobNote ",
                    new string[] { "@IDJobNote" },
                    new object[] { IDJobNote },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

    }
}
